//
//  RBConfirmOrderVC.m
//  zhongzhenglu
//
//  Created by XL on 2022/8/18.
//

#import "RBConfirmOrderVC.h"
#import <UIImage+YYAdd.h>
#import "RBTextField.h"
#import "RBGradientView.h"
#import "RBConfirmOrderResponse.h" //model
#import "RBInvoiceHeaderManageVC.h" //开票
#import "RBAddresssListVC.h" //选择地址
#import "RBCashierVC.h" //收银台
#import "RBAddressDetailResponse.h"
#import "RBCartSpecVC.h"
#import "RBGoodsConfirmChooseCouponPopVC.h"

@interface RBConfirmOrderVC ()
//地址
@property (nonatomic, strong) IBOutlet UIView *addressView;
@property (nonatomic, strong) IBOutlet UILabel *addressNameL;
@property (nonatomic, strong) IBOutlet UILabel *addressL;
//自提
@property (nonatomic, strong) IBOutlet UIView *ziti_addressView;
@property (nonatomic, strong) IBOutlet UILabel *ziti_addressL;

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UILabel *priceL; //价格
@property (nonatomic, strong) RBTextField *remarkF; //留言
@property (nonatomic, strong) UILabel *couponL;
@property (nonatomic, strong) UILabel *xnbL;
@property (nonatomic, strong) UILabel *invoiceL;
@property (nonatomic, strong) UILabel *integralL;
/** 0 快递 1自取 */
@property (nonatomic, assign) NSInteger addressTypeIndex;
/** 0 不使用 1使用 */
@property (nonatomic, assign) NSInteger integralIndex;

@property (nonatomic, strong) RBConfirmOrderResponse *response;

//地址model
@property (nonatomic, strong) RBAddressListModel *addressModel;
@property (nonatomic, strong) RBGroupStartZitiModel *zitiModel;
//发票
@property (nonatomic, strong) RBInvoiceHeaderManageModel *invoiceModel;

@end

@implementation RBConfirmOrderVC

#pragma mark - Lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setup];
    [self getData];
}

#pragma mark - Private
- (void)setup {
    self.title = @"确认订单";
    self.view.backgroundColor = [RBThemeConfig bgGrayColor];
    self.addressNameL.numberOfLines = 0;
    self.addressL.numberOfLines = 0;
    [self.addressView rbAddTapGesWithTarget:self action:@selector(addressViewTapped)];
    [self.ziti_addressView rbAddTapGesWithTarget:self action:@selector(zitiAddressViewTapped)];
    self.bottomView.hidden = YES;
    self.integralIndex = 0;
}

- (void)fillData {
    //model
    RBConfirmOrderModel *model = self.response.data;
    //地址model
    if (model.user_address && model.user_address.name.length > 0) {
        self.addressModel = model.user_address;
    }
    //刷新地址
    [self reloadAddressDisplay];
    //刷新价格
    [self reloadPrice];
    //底部显示
    self.bottomView.hidden = NO;
    //页面数据
    [self.scrollView rbSetContentWidth:kRBMainScreenWidth];
    //地址
    [self.scrollView addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(10)];
        [view view_addView:({
            UIView *view = UIView.new;
            [view h_view_addView:[self addressTypeViewWithTitle:@"快递邮寄" tag:0] withHeight:CGFLOAT_MIN width:Zoom(175) top:0 bottom:0 left:0 right:CGFLOAT_MIN centerY:NO];
            [view h_view_addView:[self addressTypeViewWithTitle:@"门店自提" tag:1] withHeight:CGFLOAT_MIN width:Zoom(175) top:0 bottom:0 left:0 right:CGFLOAT_MIN centerY:NO];
            view;
        }) withHeight:Zoom(50) width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
        [view view_addView:({
            UIView *view = UIView.new;
            view.backgroundColor = [RBThemeConfig lineGrayColor];
            view;
        }) withHeight:1 width:Zoom(326) top:0 bottom:0 left:0 right:0 centerX:1];
        if (self.addressTypeIndex == 0) {
            [view view_addView:self.addressView withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:0 left:0 right:0 centerX:0];
        } else {
            [view view_addView:self.ziti_addressView withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
        }
        view;
    }) withHeight:CGFLOAT_MIN width:Zoom(350) top:Zoom(10) bottom:0 left:CGFLOAT_MIN right:CGFLOAT_MIN centerX:YES];
    //店铺+商品
    [self.scrollView addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        //店铺
        [view view_addView:[self shopViewWithData:model] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
        //商品
        [view view_addView:[self goodsViewWithData:model] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(16) bottom:Zoom(22) left:0 right:0 centerX:0];
        
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:Zoom(22) left:Zoom(15) right:Zoom(15) centerX:0];
    //备注
    [self.scrollView addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        
        [view view_addView:({
            UIView *view = [self itemWithTitle:@"备注" placeholder:@"无备注"];
            RBTextField *F = (RBTextField *)[view viewWithTag:333];
            self.remarkF = F;
            view;
        }) withHeight:Zoom(37) width:CGFLOAT_MIN top:Zoom(12) bottom:Zoom(12) left:0 right:0 centerX:0];
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:Zoom(10) left:Zoom(15) right:Zoom(15) centerX:0];
    //商品金额
    [self.scrollView addView:({
        UIView *view = UIView.new;
        view.backgroundColor = UIColor.whiteColor;
        [view rbSetCornerRadius:Zoom(8)];
        
        [view view_addView:({
            UIView *view = [self itemWithTitle:@"商品金额" des:[NSString stringWithFormat:@"¥%@", model.good_price] needArrow:NO];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(24) bottom:Zoom(24) left:0 right:0 centerX:0];
        [view view_addView:({
            NSString *des = @"";
            if (model.coupons.count > 0) {
                des = @"-¥0.00";
            } else {
                des = @"暂无优惠券";
            }
            UIView *view = [self itemWithTitle:@"优惠券" des:des needArrow:YES];
            UILabel *couponL = [view viewWithTag:333];
            self.couponL = couponL;
            
            [view rbAddTapGesWithTarget:self action:@selector(couponViewTapped)];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(24) bottom:Zoom(24) left:0 right:0 centerX:0];
        [view view_addView:({
            NSString *des = @"暂无虚拟币";
            
            UIView *view = [self itemWithTitle:@"虚拟币" des:des needArrow:YES];
            UILabel *xnbL = [view viewWithTag:333];
            self.xnbL = xnbL;
            [view rbAddTapGesWithTarget:self action:@selector(xnbViewTapped)];
            
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(24) bottom:Zoom(24) left:0 right:0 centerX:0];
        if ([self.response.data.is_jifen isEqualToString:@"1"]) {
            [view view_addView:[self integralBackView] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(24) bottom:Zoom(24) left:0 right:0 centerX:0];
        }
        
        [view view_addView:({
            UIView *view = [self itemWithTitle:@"发票" des:@"无需发票" needArrow:YES];
            UILabel *invoiceL = [view viewWithTag:333];
            self.invoiceL = invoiceL;
            [view rbAddTapGesWithTarget:self action:@selector(chooseInvoiceTapped)];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(24) bottom:Zoom(24) left:0 right:0 centerX:0];
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(10) bottom:Zoom(10) left:Zoom(15) right:Zoom(15) centerX:NO];
}
//刷新地址
- (void)reloadAddressDisplay {
    if (self.addressModel) {
        self.addressNameL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
            [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(15)] color:[RBThemeConfig textBlackColor] string:[NSString stringWithFormat:@"收货人：%@", self.addressModel.name] lineSpacing:Zoom(4)];
            [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(15)] color:[RBThemeConfig textBlackColor] string:@"　" lineSpacing:Zoom(4)];
            [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[UIColor colorWithHexString:@"#969593"] string:self.addressModel.mobile lineSpacing:Zoom(4)];
        }];
        self.addressL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
            [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(14)] color:[UIColor colorWithHexString:@"#4D4948"] string:[NSString stringWithFormat:@"%@ %@ %@ %@", self.addressModel.province, self.addressModel.city, self.addressModel.area, self.addressModel.address] lineSpacing:Zoom(4)];
        }];
    } else {
        self.addressNameL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
            [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(15)] color:[RBThemeConfig textBlackColor] string:@"收货地址" lineSpacing:Zoom(4)];
            }];
        self.addressL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
            [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(14)] color:[UIColor colorWithHexString:@"#4D4948"] string:@"请选择" lineSpacing:Zoom(4)];
        }];
    }
    if (self.zitiModel) {
        NSMutableString *stringM = NSMutableString.string;
        [stringM appendFormat:@"门店:%@",self.zitiModel.title];
        [stringM appendFormat:@"\n地址:%@ %@ %@ %@",kRBNotNilString(self.zitiModel.add_pro),kRBNotNilString(self.zitiModel.add_city),kRBNotNilString(self.zitiModel.add_area), kRBNotNilString(self.zitiModel.address)];
        [stringM appendFormat:@"\n营业时间:%@ %@",kRBNotNilString(self.zitiModel.yingye_week),kRBNotNilString(self.zitiModel.yingye_time)];
        self.ziti_addressL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
            [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[UIColor colorWithHexString:@"#4D4948"] string:stringM lineSpacing:Zoom(7)];
        }];;
    } else {
        self.ziti_addressL.text = @"请选择自提点";
    }
}
//计算价格
- (CGFloat)calculationPrice {
    RBConfirmOrderModel *model = self.response.data;
    CGFloat total_price = [model.good_price floatValue];
    //优惠券
    if (model.total_coupon_price && model.total_coupon_price.length > 0) {
        total_price = total_price - [model.total_coupon_price floatValue];
    }
    //虚拟币
    //积分
    if ([model.is_jifen isEqualToString:@"1"]) {
        if (self.integralIndex == 1) {
            total_price = total_price - [model.jifen_bili floatValue];
        }
    }
    
    return total_price;
}
//刷新价格
- (void)reloadPrice {
    NSString *priceString = [NSString stringWithFormat:@"%.2f", [self calculationPrice]];
    
    self.priceL.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
        [maker addAttributeStringWithFont:[UIFont systemFontOfSize:Zoom(13)] color:[RBThemeConfig textBlackColor] string:@"合计"];
        [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(16)] color:[RBThemeConfig priceRedColor] string:@"¥"];
        [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(21)] color:[RBThemeConfig priceRedColor] string:priceString];
//        [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(14)] color:[RBThemeConfig priceRedColor] string:@".00"];
    }];
}

#pragma mark - Network

- (void)getData {
    __weak typeof(self) weak_self = self;
    [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
        dicM[@"cart_id"] = self.cartId;
    } path:@"api/cart_info" post:YES log:YES responseClass:RBConfirmOrderResponse.class desView:self.view showHud:YES showPlaceHolder:NO sucBlock:^(RBConfirmOrderResponse *data) {
        weak_self.response = data;
        [weak_self fillData];
    } failBlock:^(RBConfirmOrderResponse *data) {
        [weak_self.view showTip:data.message completion:nil];
    } reloadBlock:nil];
}


#pragma mark - Event
//选择配送方式
- (void)addressTypeItemViewTapped: (UITapGestureRecognizer *)ges {
    if(self.addressTypeIndex == ges.view.tag) return;
    self.addressTypeIndex = ges.view.tag;
    [self fillData];
}
//选择地址
- (void)addressViewTapped {
    __weak typeof(self) weak_self = self;
    RBAddresssListVC *vc = RBAddresssListVC.new;
    vc.selectBlock = ^(RBAddressListModel *model) {
        weak_self.addressModel = model;
        [weak_self reloadAddressDisplay];
    };
    [self.navigationController pushViewController:vc animated:YES];
}
//选择自提地址
- (void)zitiAddressViewTapped {
    RBConfirmOrderModel *model = self.response.data;
    NSMutableArray *titleArray = NSMutableArray.array;
    for (RBGroupStartZitiModel *zitiModel in model.ziti_list) {
        [titleArray addObject:zitiModel.title];
    }
    LCWeakSelf;
    [JKAction showTitle:@"请选择自提点" message:nil btnArray:titleArray completion:^(int index) {
        weakSelf.zitiModel = model.ziti_list[index];
        [weakSelf reloadAddressDisplay];
    }];
}
//积分选择
- (void)chooseIntegralTap:(UIGestureRecognizer *)ges {
    RBConfirmOrderModel *model = self.response.data;
    if ([model.user_jifen floatValue] < [model.max_jifen floatValue] && ges.view.tag == 1) {
        [self.view showTip:@"积分不足" completion:nil];
        return;
    }
    if (self.integralIndex == ges.view.tag) return;
    self.integralIndex = ges.view.tag;
    
    UIImageView *aImageView = [ges.view.superview viewWithTag:100];
    UIImageView *bImageView = [ges.view.superview viewWithTag:101];
    aImageView.image = [UIImage imageNamed:@"unsel"];
    bImageView.image = [UIImage imageNamed:@"unsel"];
    
    NSString *integralString = @"";
    if (ges.view.tag == 0) {
        aImageView.image = [UIImage imageNamed:@"addressListDefault"];
        integralString = @"";
    } else {
        bImageView.image = [UIImage imageNamed:@"addressListDefault"];
        integralString = [NSString stringWithFormat:@"(-¥%@)", self.response.data.jifen_bili];
    }
    NSString *integral = [NSString stringWithFormat:@"积分%@", integralString];
    self.integralL.attributedText =
    [NSString changeSectionColorWithString:integral color:[RBThemeConfig priceRedColor] from:2 lenth:integral.length - 2];
//        [NSString changeSectionFontAndColorWithString:integral font:[UIFont systemFontOfSize:11] color:[RBThemeConfig priceRedColor] from:2 lenth:(integral.length - 2)];
    
    //刷新价格
    [self reloadPrice];
}
//查看规格
- (void)specViewTapped {
    RBCartSpecVC *vc = RBCartSpecVC.new;
    vc.cartSpecArray = self.response.data.spec_key_name;
    [self.navigationController pushViewController:vc animated:YES];
}
//优惠券选择
- (void)couponViewTapped {
    if (self.response.data.coupons.count == 0) {
        [self.view showTip:@"暂无可使用的优惠券" completion:nil];
        return;
    }
    RBGoodsConfirmChooseCouponPopVC *vc = RBGoodsConfirmChooseCouponPopVC.new;
    vc.data = self.response.data.coupons;
    [self presentVc:vc];
}
//虚拟币选择
- (void)xnbViewTapped {
    
}
//发票选择
- (void)chooseInvoiceTapped {
    LCWeakSelf;
    [JKAction showTitle:nil message:nil btnArray:@[@"无需发票", @"选择发票"] completion:^(int index) {
        if (index == 0) {
            weakSelf.invoiceL.text = @"无需发票";
            weakSelf.invoiceModel = nil;
        } else {
            RBInvoiceHeaderManageVC *vc = RBInvoiceHeaderManageVC.new;
            vc.block = ^(RBInvoiceHeaderManageModel * _Nonnull model) {
                weakSelf.invoiceModel = model;
                weakSelf.invoiceL.text = model.company_name;
            };
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }
    }];
}

//提交订单
- (void)commitBtnTapped {
    if (self.addressTypeIndex == 0 && !self.addressModel) {
        [self.view showTip:@"请选择收件地址" completion:nil];
        return;
    }
    if (self.addressTypeIndex == 1 && !self.zitiModel) {
        [self.view showTip:@"请选择自提点" completion:nil];
        return;
    }
    
    RBConfirmOrderModel *model = self.response.data;
    
    NSString *priceString = [NSString stringWithFormat:@"%.2f", [self calculationPrice]];
    LCWeakSelf;
    [self viewLoadDataWithParam:^(NSMutableDictionary *dicM) {
        dicM[@"cart_id"] = self.cartId;
        dicM[@"user_id"] = [RBAccountManager getUserId];
        dicM[@"total_freight"] = @"0.00";
        dicM[@"total_price"] = priceString;
        dicM[@"mail_type"] = @(self.addressTypeIndex + 1);
        dicM[@"remark"] = self.remarkF.text;
        
        if (self.addressTypeIndex == 0) {
            dicM[@"user_address_id"] = self.addressModel.add_id;
        } else {
            dicM[@"zt_id"] = self.zitiModel.zt_id;
        }
        
        if (model.total_coupon_price && model.total_coupon_price.length > 0) {
            dicM[@"used_platform_member_coupon_id"] = model.used_platform_member_coupon_id;
            dicM[@"total_coupon_price"] = model.total_coupon_price;
        }
        if (self.integralIndex == 1) {
            dicM[@"total_jifen"] = model.max_jifen; //积分
        }
        if (self.invoiceModel && self.invoiceModel.id.length > 0) {
            dicM[@"fapiao_list_id"] = self.invoiceModel.id;
        }
    } path:_Order_create post:YES log:YES responseClass:RBConfirmOrderSubmitResponse.class desView:self.view showHud:YES showPlaceHolder:NO sucBlock:^(RBConfirmOrderSubmitResponse *data) {
        if (data.succeed) {
            RBCashierVC *vc = RBCashierVC.new;
            vc.order_id = data.data.goods.order_id;
            vc.order_num = data.data.order_number;
            vc.order_price = data.data.total_price;
            vc.order_type = data.data.order_type;
            [weakSelf.navigationController pushViewController:vc animated:YES];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                NSMutableArray *navigationArray = [NSMutableArray arrayWithArray:weakSelf.navigationController.viewControllers];
                [navigationArray removeObjectAtIndex:(navigationArray.count - 2)];
                weakSelf.navigationController.viewControllers = navigationArray;
            });
        }
    } failBlock:^(RBConfirmOrderSubmitResponse *data) {
        [weakSelf.view showTip:data.message completion:nil];
    } reloadBlock:nil];
}

#pragma mark - Setter

#pragma mark - Getter
//scrollView
- (UIScrollView *)scrollView {
    if (!_scrollView) {
        self.scrollView = ({
            UIScrollView *view = UIScrollView.new;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.top.mas_equalTo(0);
                make.bottom.mas_equalTo(self.bottomView.mas_top);
            }];
            view;
        });
    }
    return _scrollView;
}
//选择配送方式
- (UIView *)addressTypeViewWithTitle:(NSString *)title tag: (NSInteger)tag {
    UIView *view = UIView.new;
    view.tag = tag;
    [view rbAddTapGesWithTarget:self action:@selector(addressTypeItemViewTapped:)];
    [view view_addView:({
        UIView *view = UIView.new;
        [view h_view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:self.addressTypeIndex == tag? @"addressListDefault": @"unsel"] withHeight:Zoom(15) width:Zoom(15) top:0 bottom:0 left:0 right:0 centerY:1];
        [view h_view_addView:[RanTool labelWithFontSize:Zoom(14) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:title] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(10) right:0 centerY:0];
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:1];
    return view;
}
//店铺信息
- (UIView *)shopViewWithData:(RBConfirmOrderModel *)data {
    UIView *view = UIView.new;
    
    [view h_view_addView:[RanTool labelWithFontSize:Zoom(16) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:data.shop_name] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(16) bottom:Zoom(16) left:Zoom(12) right:Zoom(12) centerY:NO];
    
    return view;
}
//商品信息
- (UIView *)goodsViewWithData:(RBConfirmOrderModel *)data {
    UIView *view = UIView.new;
    
    [view view_addView:({
        UIView *view = UIView.new;
        [view h_view_addView:[RanTool imgViewWithMode:2 radius:Zoom(5) imgName:data.picurl] withHeight:Zoom(72) width:Zoom(82) top:0 bottom:CGFLOAT_MIN left:Zoom(12) right:CGFLOAT_MIN centerY:NO];
        [view h_view_addView:({
            UIView *view = UIView.new;
            [view view_addView:({
                UILabel *view = [RanTool labelWithFontSize:Zoom(16) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:data.good_name];
                view.numberOfLines = 2;
                view;
            }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
            [view view_addView:({
                UIView *view = UIView.new;
                [view h_view_addView:({
                    UIView *view = UIView.new;
                    [view rbAddTapGesWithTarget:self action:@selector(specViewTapped)];
                    view.backgroundColor = [RBThemeConfig bgGrayColor];
                    [view rbSetCornerRadius:Zoom(11)];
                    [view h_view_addView:({
                        UILabel *view = [RanTool labelWithFontSize:Zoom(11) weight:0 color:[RBThemeConfig textGrayColor] align:0 text:@"查看规格"];
                        [view addPriority:1];
                        view;
                    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(9) right:Zoom(9) centerY:0];
                    view;
                }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
                [view h_view_addView:UILabel.new withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
//                [view h_view_addView:({
//                    UILabel *view = [RanTool labelWithFontSize:Zoom(12) weight:0 color:[RBThemeConfig textLightBlackColor] align:0 text:[NSString stringWithFormat:@"x%@", data.name]];
//                    [view addPriority:2];
//                    view;
//                }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:0 centerY:YES];
                view;
            }) withHeight:Zoom(22) width:CGFLOAT_MIN top:Zoom(9) bottom:0 left:0 right:0 centerX:NO];
            [view view_addView:({
                UILabel *view = UILabel.new;
                view.attributedText = [RanTool attributeStringMaker:^(NSMutableArray *maker) {
                    [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(11)] color:[RBThemeConfig priceRedColor] string:@"¥"];
                    [maker addAttributeStringWithFont:[UIFont boldSystemFontOfSize:Zoom(15)] color:[RBThemeConfig priceRedColor] string:data.good_price];
                }];
                view;
            }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:Zoom(12) bottom:0 left:0 right:0 centerX:0];
            view;
        }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:Zoom(8) centerY:NO];
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:NO];
    
    return view;
}
//备注
- (UIView *)itemWithTitle: (NSString *)title placeholder: (NSString *)placeholder {
    UIView *view = UIView.new;
    
    UILabel *titleL = [RanTool labelWithFontSize:Zoom(13) weight:0 color:@"#333333" align:0 text:title];
    [titleL addPriority:10];
    [view h_view_addView:titleL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(16) right:0 centerY:0];
    
    RBTextField *textF = RBTextField.new;
    [view addSubview:textF];
    textF.font = [UIFont systemFontOfSize:Zoom(13)];
    textF.textColor = [RBThemeConfig textBlackColor];
    textF.textAlignment = NSTextAlignmentRight;
    textF.placeholder = placeholder;
    textF.tag = 333;
    [view h_view_addView:textF withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:0 centerY:0];
    
    [view h_view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"mine_arrow_right"] withHeight:Zoom(12) width:Zoom(7) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:Zoom(16) centerY:YES];
    
    return view;
}
//左右
- (UIView *)itemWithTitle: (NSString *)title des: (NSString *)des needArrow: (BOOL)needArrow {
    UIView *view = UIView.new;
    
    UILabel *titleL = [RanTool labelWithFontSize:Zoom(13) weight:0 color:@"#333333" align:0 text:title];
    [view addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(Zoom(16));
        make.top.bottom.mas_equalTo(0);
    }];
    [view h_view_addView:titleL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(16) right:0 centerY:0];
    
    UILabel *desL = [RanTool labelWithFontSize:Zoom(13) weight:0 color:@"#333333" align:0 text:des];
    desL.tag = 333;
    [desL addPriority:1];
    [view addSubview:desL];
    [view h_view_addView:desL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(12) right:Zoom(16) centerY:0];

    if (needArrow)
    {
        [view h_view_addView:[RanTool imgViewWithMode:1 radius:0 imgName:@"mine_arrow_right"] withHeight:Zoom(12) width:Zoom(7) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:Zoom(12) right:Zoom(16) centerY:YES];
    }
    
    return view;
}
//积分
- (UIView *)integralBackView {
    UIView *view = UIView.new;
    
    UILabel *titleL = [RanTool labelWithFontSize:Zoom(13) weight:0 color:@"#333333" align:0 text:@"积分"];
    self.integralL = titleL;
    [view addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(Zoom(16));
        make.top.bottom.mas_equalTo(0);
    }];
    [view h_view_addView:titleL withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(16) right:CGFLOAT_MIN centerY:0];
    
    [view h_view_addView:[self integralChooseWith:@"使用" tag:1] withHeight:CGFLOAT_MIN width:Zoom(60) top:0 bottom:0 left:CGFLOAT_MIN right:Zoom(10) centerY:NO];

    [view h_view_addView:[self integralChooseWith:@"不使用" tag:0] withHeight:CGFLOAT_MIN width:Zoom(60) top:0 bottom:0 left:Zoom(10) right:Zoom(16) centerY:NO];
    
    return view;
}
//选择积分使用
- (UIView *)integralChooseWith:(NSString *)title tag: (NSInteger)tag {
    UIView *view = UIView.new;
    view.tag = tag;
    [view rbAddTapGesWithTarget:self action:@selector(chooseIntegralTap:)];
    [view view_addView:({
        UIView *view = UIView.new;
        [view h_view_addView:({
            UIImageView *imageView = [RanTool imgViewWithMode:1 radius:0 imgName:self.integralIndex == tag? @"addressListDefault": @"unsel"];
            imageView.tag = 100 + tag;
            imageView;
        }) withHeight:Zoom(15) width:Zoom(15) top:0 bottom:0 left:0 right:0 centerY:1];
        [view h_view_addView:[RanTool labelWithFontSize:Zoom(14) weight:0 color:[RBThemeConfig textBlackColor] align:0 text:title] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(10) right:0 centerY:0];
        view;
    }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:1];
    return view;
}
//底部view
- (UIView *)bottomView {
    if (!_bottomView) {
        self.bottomView = ({
            UIView *view = UIView.new;
            [self.view addSubview:view];
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.bottom.mas_equalTo(0);
                make.height.mas_equalTo(kRBSafeBottomHeight + Zoom(60));
            }];
            view.backgroundColor = UIColor.whiteColor;
            
            UIView *toolBar = UIView.new;
            [view addSubview:toolBar];
            [toolBar mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.top.mas_equalTo(0);
                make.height.mas_equalTo(Zoom(60));
            }];
            
            [toolBar h_view_addView:({
                UIView *priceV = UIView.new;
                
                [priceV h_view_addView:({
                    UILabel *view = [RanTool labelWithFontSize:Zoom(13) weight:0 color:@"#333333" align:0 text:@""];
                    self.priceL = view;
                    view;
                }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerY:0];
                priceV;
            }) withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:Zoom(13) right:Zoom(5) centerY:0];
            
            [toolBar h_view_addView:({
                RBGradientView *view = [RBGradientView gradientViewWithColors:@[[UIColor colorWithHexString:@"#518CFF"], [UIColor colorWithHexString:@"#2A6DF0"]] locations:nil vertical:NO];
                [view rbSetCornerRadius:Zoom(20)];
                [view rbAddTapGesWithTarget:self action:@selector(commitBtnTapped)];
                [view view_addView:[RanTool labelWithFontSize:Zoom(15) weight:0 color:UIColor.whiteColor align:1 text:@"提交订单"] withHeight:CGFLOAT_MIN width:CGFLOAT_MIN top:0 bottom:0 left:0 right:0 centerX:0];
                view;
            }) withHeight:Zoom(40) width:Zoom(106) top:CGFLOAT_MIN bottom:CGFLOAT_MIN left:0 right:Zoom(13) centerY:YES];
            
            view;
        });
    }
    return _bottomView;
}



@end
